﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class CreateExcel_CreatePlanInfoExcel : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        Cisoft.YiWu.BLL.PlanInfoBO bllshow = new Cisoft.YiWu.BLL.PlanInfoBO();
        DataSet ds = new DataSet();

        string startTime = "";
        string endTime = "";
        string txtField = "";
        string txtFieldname = "";
        string lblHospitalID="";
        string ddlDep="";
        string ddltime = "";

        if (Request.QueryString["startTime"] != null && Request.QueryString["startTime"].ToString() != "")
        {
            startTime = Request.QueryString["startTime"].ToString();
        }
        if (Request.QueryString["endTime"] != null && Request.QueryString["endTime"].ToString() != "")
        {
            endTime = Request.QueryString["endTime"].ToString();
        }
        if (Request.QueryString["txtField"] != null && Request.QueryString["txtField"].ToString() != "")
        {
            txtField = Request.QueryString["txtField"].ToString();
        }
        if (Request.QueryString["txtFieldname"] != null && Request.QueryString["txtFieldname"].ToString() != "")
        {
            txtFieldname = Request.QueryString["txtFieldname"].ToString();
        }
        if (Request.QueryString["lblHospitalID"] != null && Request.QueryString["lblHospitalID"].ToString() != "")
        {
            lblHospitalID = Request.QueryString["lblHospitalID"].ToString();
        }
        if (Request.QueryString["ddlDep"] != null && Request.QueryString["ddlDep"].ToString() != "")
        {
            ddlDep = Request.QueryString["ddlDep"].ToString();
        }
        if (Request.QueryString["ddltime"] != null && Request.QueryString["ddltime"].ToString() != "")
        {
            ddltime = Request.QueryString["ddltime"].ToString();
        }


        ds = bllshow.GetListFourInfo(startTime, endTime, txtFieldname, txtField, lblHospitalID, ddlDep, ddltime);

        GetData(ds);
        ShowExcel();
    }

    public void GetData(DataSet ds)
    {
        gvData.DataSource = ds;
        gvData.DataBind();
    }

    public void ShowExcel()
    {


        Response.Clear();
        Response.Buffer = false;
        Response.Charset = "GB2312";
        Response.AppendHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode("预约记录", System.Text.Encoding.UTF8) + ".xls");


        Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
        Response.ContentType = "application/ms-excel";
        Response.Write("<meta http-equiv=Content-Type content=\"text/html; charset=GB2312\">");
        this.EnableViewState = false;
        System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
        HtmlTextWriter oHtmlTextWriter = new HtmlTextWriter(oStringWriter);
        gvData.RenderControl(oHtmlTextWriter);
        Response.Write(oStringWriter.ToString());
        Response.End();
    }

    public override void VerifyRenderingInServerForm(Control control)
    {
    }
    protected void lbtn_Click(object sender, EventArgs e)
    {
        ShowExcel();
    }
    protected void gvData_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //Label LblNum = (Label)e.Row.FindControl("LblNum");
            //LblNum.Text = (e.Row.DataItemIndex + 1).ToString();


            ////人才的居住地绑定
            //Label LblArea = (Label)e.Row.FindControl("LblArea");

            //string strArea = DataBinder.Eval(e.Row.DataItem, "RsIn_AddNow").ToString();

            //if (strArea != "")
            //{
            //    string[] arrArea;

            //    arrArea = strArea.Split('|');
            //    int iArea = arrArea.Length - 1;
            //    LblArea.Text = arrArea[iArea];
            //}
            //else
            //{
            //    LblArea.Text = "刚注册未填写";
            //}
            ////查询注册时间
            //Label lblStarteTime = (Label)e.Row.FindControl("lblStarteTime");
            //string strTimeA = "";
            //if (Request.QueryString["TimeA"] != null)
            //{
            //    strTimeA = Request.QueryString["TimeA"].ToString();
            //}
            //if (strTimeA != "")
            //{
            //    lblStarteTime.Text = strTimeA;
            //}
            //else
            //{
            //    lblStarteTime.Text = "未设定";
            //}

            //Label lblEndTime = (Label)e.Row.FindControl("lblEndTime");
            //string strTimeB = "";
            //if (Request.QueryString["TimeB"] != null)
            //{
            //    strTimeB = Request.QueryString["TimeB"].ToString();
            //}
            //if (strTimeB != "")
            //{
            //    lblEndTime.Text = strTimeB;
            //}
            //else
            //{
            //    lblEndTime.Text = "至今";
            //}
        }
    }
}
